package org.zjh.view.game;

import org.zjh.constant.ImageConstant;
import org.zjh.controller.listener.ExitLis;
import org.zjh.controller.listener.MenuListener;

import javax.swing.*;
import java.awt.*;

/**
 * @description: 游戏窗口
 * @author 郑佳豪
 * @date 2024/10/4 2:21
 * @version 1.0
 */
public class GameFrame extends JFrame {
    public static final int WIDTH = 1200;
    public static final int HEIGHT = 720;

    private GamePanel gamePanel;

    private JMenuItem start;
    private JMenuItem pause;
    private JMenuItem continueGame;
    private JMenuItem restart;
    private JMenuItem quit;
    private JMenuItem aboutAuthor;
    private JMenuItem aboutGame;



    public GameFrame(){
        //调用初始化构造方法
        init();
        //调用监听器注册方法
        addListener();
    }

    /**
     * 初始化
     */
    private void init(){
        setLayout(new BorderLayout());
        // 设置窗口的大小
        setSize(WIDTH,HEIGHT);
        //创建登入面板
        gamePanel = new GamePanel();
        //设置居中显示
        setLocationRelativeTo(null);
        // 设置关闭操作
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        //设置窗口标题
        setTitle("欢乐斗地主");
        // 设置窗口不可调节大小
        setResizable(false);
        //添加面板
        add(gamePanel);
        //设置窗口图片LOGO
        setIconImage(ImageConstant.Frame_Title_IMAGE.getImage());
        //设置菜单栏
        setMenuBar();
        //设置窗口可见
        setVisible(true);
    }


    /**
     * 设置菜单栏
     */
    private void setMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        JMenu operatorMenu = new JMenu("操作菜单");
        start = new JMenuItem("开始游戏");
        pause = new JMenuItem("暂停游戏");
        continueGame = new JMenuItem("继续游戏");
        restart = new JMenuItem("重新开始游戏");
        quit = new JMenuItem("退出游戏界面");

        //设置一些按钮默认不可点击
        pause.setEnabled(false);
        restart.setEnabled(false);
        continueGame.setEnabled(false);


        //注册监听
        operatorMenu.add(start);
        operatorMenu.add(pause);
        operatorMenu.add(continueGame);
        operatorMenu.add(restart);
        operatorMenu.add(quit);
        JMenu aboutMenu = new JMenu("关于菜单");
        aboutAuthor = new JMenuItem("关于作者");
        aboutGame = new JMenuItem("关于游戏");
        aboutMenu.add(aboutAuthor);
        aboutMenu.add(aboutGame);
        menuBar.add(operatorMenu);
        menuBar.add(aboutMenu);
        this.setJMenuBar(menuBar);
    }



    /**
     * 添加程序退出监听器
     */
    private void addListener(){
        addWindowListener(ExitLis.getInstance());
        MenuListener menuListener = new MenuListener();
        //设置监听指令
        start.setActionCommand("start");
        pause.setActionCommand("pause");
        continueGame.setActionCommand("continueGame");
        restart.setActionCommand("restart");
        quit.setActionCommand("quit");
        aboutAuthor.setActionCommand("aboutAuthor");
        aboutGame.setActionCommand("aboutGame");

        //注册监听
        start.addActionListener(menuListener);
        pause.addActionListener(menuListener);
        continueGame.addActionListener(menuListener);
        restart.addActionListener(menuListener);
        quit.addActionListener(menuListener);
        aboutAuthor.addActionListener(menuListener);
        aboutGame.addActionListener(menuListener);



    }

    public GamePanel getGamePanel() {
        return gamePanel;
    }


    public void setGamePanel(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
    }

    public JMenuItem getStart() {
        return start;
    }

    public void setStart(JMenuItem start) {
        this.start = start;
    }

    public JMenuItem getPause() {
        return pause;
    }

    public void setPause(JMenuItem pause) {
        this.pause = pause;
    }

    public JMenuItem getRestart() {
        return restart;
    }

    public void setRestart(JMenuItem restart) {
        this.restart = restart;
    }

    public JMenuItem getQuit() {
        return quit;
    }

    public void setQuit(JMenuItem quit) {
        this.quit = quit;
    }

    public JMenuItem getAboutAuthor() {
        return aboutAuthor;
    }

    public void setAboutAuthor(JMenuItem aboutAuthor) {
        this.aboutAuthor = aboutAuthor;
    }

    public JMenuItem getAboutGame() {
        return aboutGame;
    }

    public void setAboutGame(JMenuItem aboutGame) {
        this.aboutGame = aboutGame;
    }

    public JMenuItem getContinueGame() {
        return continueGame;
    }

    public void setContinueGame(JMenuItem continueGame) {
        this.continueGame = continueGame;
    }
}
